#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from socketserver import BaseRequestHandler, ThreadingTCPServer


class EchoHandler(BaseRequestHandler):
    def handle(self):
        print("Got connection from {0}:{1}".format(self.client_address[0], self.client_address[1]))
        while True:
            msg = self.request.recv(8192)
            print("Got msg:", msg)
            if not msg:
                break
            self.request.send(msg)


if __name__ == '__main__':
    serv = ThreadingTCPServer(('', 20000), EchoHandler)
    print("Server started on 127.0.0.1, port 20000.....")
    serv.serve_forever()
